﻿using Cinema.Model.EF;

namespace Cinema.Tests.Common
{
    public class TestsUnitOfWork : UnitOfWork
    {
        public void ResetDatabase()
        {
            _cinemaContext.Database.ExecuteSqlCommand("EXEC sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'");
            _cinemaContext.Database.ExecuteSqlCommand("EXEC sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'");
            _cinemaContext.Database.ExecuteSqlCommand("EXEC sp_MSforeachtable 'DELETE FROM ?'");
            _cinemaContext.Database.ExecuteSqlCommand("EXEC sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'");
            _cinemaContext.Database.ExecuteSqlCommand("EXEC sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'");

            try
            {
                _cinemaContext.Database.ExecuteSqlCommand("EXEC sp_MSforeachtable \"DBCC CHECKIDENT ( '?', RESEED, 0)\"");
            }
            catch
            {}
        }
    }
}
